//
//  AppDelegate.m
//  DongChiDaChiProject1
//
//  Created by lanou3g on 15/10/27.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "AppDelegate.h"
#import "RootViewController.h"
#import "UMSocial.h"

#import "UserCollectData.h"
#import <AVOSCloud/AVOSCloud.h>
#define kLeanCloudAppID @"gA6uTXMkBJ123OiHmOhCYYMc"
#define kLeanCloudAppKey @"V8ieE1qSiRNpcXL5sHJ1IHr5"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:self.window.bounds];
    imageV.image = [UIImage imageNamed:@"toubiao3.jpg"];
    
    [self.window addSubview:imageV];
    [self.window bringSubviewToFront:imageV];
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationDelegate:self];
    
    imageV.alpha = 0.0;
    imageV.frame = self.window.bounds;
    
    [UIView commitAnimations];
    
    
    [NSThread sleepForTimeInterval:1.0];
    
    
    
    RootViewController *rootVC = [[RootViewController alloc] init];
    self.window.rootViewController = rootVC;
    
    // 友盟分享
    [UMSocialData setAppKey:@"5637324467e58e7690003055"];
    
    // leanCloud
    [AVOSCloud setApplicationId:kLeanCloudAppID clientKey:kLeanCloudAppKey];
    // 如果想跟踪统计应用的打开情况
    [AVAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
    
    // 注册userCollectData
    [UserCollectData registerSubclass];
    
    
    // 注册通知
    // 隐藏tab的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(NotificationInfo:) name:@"HIDDENTABBAR" object:nil];
    // 显示tab的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(NotificationInfo:) name:@"SHOWTABBAR" object:nil];
    
    
    return YES;
}

- (void)NotificationInfo:(NSNotification *)notification
{
    if ([notification.name isEqualToString:@"HIDDENTABBAR"]) {
        UIViewController *vc = self.window.rootViewController;
        self.window.rootViewController = nil;
        UITabBar *tabBar = [UITabBar appearance];
        tabBar.hidden = YES;
        self.window.rootViewController = vc;
    } else if ([notification.name isEqualToString:@"SHOWTABBAR"]) {
        UIViewController *vc = self.window.rootViewController;
        self.window.rootViewController = nil;
        UITabBar *tabBar = [UITabBar appearance];
        tabBar.hidden = NO;
        self.window.rootViewController = vc;
    }
    
    
}



- (void)applicationWillResignActive:(UIApplication *)application {
    NSLog(@"APP 将要被激活");
    NSLog(@"失去焦点 不能跟用户进行交互");
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"APP 进入后台HOME 键");
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    NSLog(@"APP 将要进入前台");
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"APP被激活");
}

- (void)applicationWillTerminate:(UIApplication *)application {
    NSLog(@"APP 将要终止 某些情况被终结时会调用这个 APP");
}

@end
